package com.ln.point.service;

import javax.annotation.Resource;

import com.ln.core.orm.PageData;
import freemarker.template.utility.StringUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ln.core.orm.hibernate.BaseDao;
import com.ln.core.orm.hibernate.BaseService;
import com.ln.point.entity.PointRecord;

import java.util.List;

@Service
@Transactional
public class PointRecordService extends BaseService<PointRecord> {


    @Override
    @Resource(name = "pointRecordDao")
    public void setBaseDao(BaseDao<PointRecord> baseDao) {
        this.baseDao = baseDao;
    }

    @Override
    public void save(PointRecord entity) {
        super.save(entity);    //To change body of overridden methods use File | Settings | File Templates.
    }

    @Override
    public PageData<PointRecord> find(PageData<PointRecord> pageData) {

        PageData<PointRecord> p = super.find(pageData);
        List<PointRecord> list = p.getResult();

        if (list != null) {
            for (PointRecord pr : list) {
                if (pr.getIdepart() == null || StringUtils.isBlank(pr.getName())) {
                    baseDao.update(pr);
                }
            }
        }

        return super.find(pageData);    //To change body of overridden methods use File | Settings | File Templates.
    }
}
